package com.vancouver.knows.ui.activity.my;

import android.content.Context;
import android.view.View;

import com.pangu.task.mark.ATaskMark;
import com.pangu.ui.refresh.ARefreshViewController;
import com.pangu.ui.refresh.RefreshControllerView;
import com.vancouver.knows.MainApplication;
import com.vancouver.knows.R;
import com.vancouver.knows.business.BusinessModule;

/**
 * 关注下拉界面
 * 
 * @author llf
 * 
 */
public class FollowedPullControllerView extends RefreshControllerView {
	private String[] titles;
	public FollowedPullControllerView(Context context) {
		super(context);
		titles = getResources().getStringArray(R.array.my_followed_array);
	}

	@SuppressWarnings("rawtypes")
	@Override
	public void onRefresh(ARefreshViewController controller) {
		((FollowedListView) content).handleRefreshLoadItem();
	}

	public void loadData(int type) {
		BusinessModule module = ((MainApplication) imContext).getBusinessModule();
		ATaskMark aTaskMark = null;
		switch (type) {
		case FollowedChildrenFragment.FOLLOWED_TYPE_ALL:
			aTaskMark = module.getTaskMarkPool().getFollowedTaskMarkTaskMark(titles[0], String.valueOf(type));
			break;
		case FollowedChildrenFragment.FOLLOWED_TYPE_CITY_NEWS:
			aTaskMark = module.getTaskMarkPool().getFollowedTaskMarkTaskMark(titles[1], String.valueOf(type));
			break;
		case FollowedChildrenFragment.FOLLOWED_TYPE_EVENTS:
			aTaskMark = module.getTaskMarkPool().getFollowedTaskMarkTaskMark(titles[2], String.valueOf(type));
			break;
		case FollowedChildrenFragment.FOLLOWED_TYPE_SHOP:
			aTaskMark = module.getTaskMarkPool().getFollowedTaskMarkTaskMark(titles[3], String.valueOf(type));
			break;
		
		}
		((FollowedListView) content).initLoadableView(type, aTaskMark);
		int count = module.getCacheManager().getMyFollowedCache().getItemInfoCount(aTaskMark);
		if (count > 0 && aTaskMark.getTaskStatus() != ATaskMark.HANDLE_WAIT
				&& aTaskMark.getTaskStatus() != ATaskMark.HANDLE_DOING) {	
			((FollowedListView) content).handleRefreshLoadItem();
		}else {
			if (count==0 && aTaskMark.getTaskStatus() != ATaskMark.HANDLE_DOING) {
				aTaskMark.reinitTaskMark();
			}
		}
	}

	public void flush() {
		((FollowedListView) content).notifyDataSetChanged();
	}

	@Override
	protected View createContentView() {
		return new FollowedListView(getContext(), this);
	}

}
